//
//  UIBarButtonItem+DXWBarButtonItem.m
//  BuDeJie
//
//  Created by 淡馨慰 on 16/7/27.
//  Copyright © 2016年 淡馨慰. All rights reserved.
//

#import "UIBarButtonItem+DXWBarButtonItem.h"

@implementation UIBarButtonItem (DXWBarButtonItem)

+ (instancetype)barButtonItemWithImage:(UIImage *)image highlightImage:(UIImage *)highlightedImage target:(id)target action:(SEL)action
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highlightedImage forState:UIControlStateHighlighted];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    //必须要自适应尺寸,否则按钮不显示
    [btn sizeToFit];
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    [btnView addSubview:btn];
    //用一个UIView包装一个button便可以解决点击btn的点击范围变大问题
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btnView];
    return item;
}

+ (instancetype)barButtonItemWithImage:(UIImage *)image selectedImage:(UIImage *)selectedImage target:(id)target action:(SEL)action
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:selectedImage forState:UIControlStateSelected];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    //必须要自适应尺寸,否则按钮不显示
    [btn sizeToFit];
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    [btnView addSubview:btn];
    //用一个UIView包装一个button便可以解决点击btn的点击范围变大问题
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btnView];
    return item;
}


@end
